"""
Python操作Mysql 使用PyMysql

"""
# 演示 PyMySQL连接数据库
from pymysql import Connection # 数据库连接对象

conn = None
try:
    # 创建数据库连接对象
    conn = Connection(
        host="localhost",
        port=3306,
        user="root",
        passwd="root",
        charset="utf8",
        database='db2'
    )
except Exception as e:
    print(e)
finally:
    if conn:
        conn.close() # 释放资源，关闭数据库

print(conn)
print(type(conn))